package com.tsingtao.arch.rule;

import static com.societegenerale.commons.plugin.utils.ArchUtils.importAllClassesInPackage;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;

import com.societegenerale.commons.plugin.rules.ArchRuleTest;
import com.societegenerale.commons.plugin.service.ScopePathProvider;
import com.tngtech.archunit.lang.syntax.elements.GivenClassesConjunction;
import java.util.Collection;

/**
 * DTO 规则检查
 */
public class DataTransferObjectRulesTest implements ArchRuleTest {

  private static final GivenClassesConjunction DTO = classes().that()
      .areTopLevelClasses().and()
      .resideInAPackage("..dto..").and()
      .areNotAnnotatedWith("lombok.Generated").and()
      .areNotInnerClasses().or()
      .haveSimpleNameEndingWith("DTO");

  @Override
  public void execute(String packagePath, ScopePathProvider scopePathProvider, Collection<String> excludedPaths) {
    DTO.should()
        .resideInAPackage("..dto..").andShould()
        .haveSimpleNameEndingWith("DTO")
        .check(importAllClassesInPackage(scopePathProvider.getMainClassesPath(), packagePath, excludedPaths));
  }

}